use ExtUtils::MakeMaker;

my $valfile = 'Valacdos.txt';

my $valtarget = $valfile;

my $subfile = 'Scsubtab.txt';

my $subtarget = $subfile;

my ($WIN32, $FLAVOUR, $PREFIX, $MAKE);

if ($^O eq 'MSWin32') {  # any others also?
    $WIN32   = 1;
    $FLAVOUR = 'Win32';
    $PREFIX  = 'C:/Program Files/Netscal/';
    $MAKE    = 'nmake';
}
else {
    $WIN32   = 0;
    $FLAVOUR = 'Unix';
    $PREFIX  = '/usr/local/share/Netscal/';
    $MAKE    = 'make';
}

print <<EE1;
Configure Netscal::BankAccount
==============================

We need to find out what to do with the datafiles that this module
needs to work.
EE1

print "\nWhat directory do you want to use for the data : [$PREFIX] ";
chomp(my $new_dir = <>);

$PREFIX = $new_dir if $new_dir;

open( CONF,">./BankAccount/Config.pm" )|| die "Can't create Config.pm - $!\n";

print CONF <<ECONF;
#
# This file was autogenerated edit at your peril
#

package Netscal::BankAccount::Config;

use strict;

use vars qw(\$valfile \$subsfile);

if ( -f "$PREFIX/$valtarget" )
{
   \$valfile = "$PREFIX/$valtarget";
}
else
{
   \$valfile = "$valtarget";
}

if ( -f "$PREFIX/$subtarget" )
{
   \$subsfile = "$PREFIX/$subtarget";
}
else
{
   \$subsfile = "$subtarget";
}

1;

ECONF

WriteMakefile(
    'NAME'		=> 'Netscal::BankAccount',
    'VERSION_FROM'	=> 'BankAccount.pm', # finds $VERSION
    'PREREQ_PM'		=> {}, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?   
      (
       AUTHOR     => 'Jonathan Stowe <gellyfish@gellyfish.com>') : ()),
);

package MY;

sub postamble
{
   return <<POST;

data_install ::
	\@\$(MKPATH) $PREFIX
	\@\$(CP) $valfile $PREFIX/$valtarget
	\@\$(CP) $subfile $PREFIX/$subtarget

POST
}

sub install
{
   my ( $self ) = @_;

   my $install = $self->SUPER::install;

   $install =~ s/^(install\s*::\s+.*)/$1 data_install/m;

   $install;
}
